# def sum(*args):
#     global sum1
#     shujv = yield
#     for i in shujv:
#         sum1 = sum1 + int(i)
#     print('sum:%d'% sum1)
# sum1 = 0
# s = sum()
# s.__next__()
# a = []
# while True:
#     a = input('shuru:').strip( ).split(',')
#     if a == 'q':
#         exit()
#     elif len(a) != 0:
#         break
# s.send(a)



# def save_back():
#     f = open(name,'r+')
#     for line in f:
#         if line in old_rong:                                #输入文件名，老内容新内容，进行替换在保存
#             line = line.replace(old_rong,new_rong)
#             f.write(line)
#     f.close()
# name = input('name:')
# old_rong = input('lrong:').strip().split(',')
# new_rong = input('nrong:').strip().split(',')
# save_back(name,old_rong,new_rong)


# def cheap(list):
#     for i in a:
#         new_i = str(i).strip()
#         if i != new_i:
#             print('有空值')
#             return
#     else:
#         print('没有')
# a = str(input(':')).split(',')
# print(a)
# cheap(a)


# d = {
# 'k1':['马纤羽', '深圳', '173', '50', '13744234523'],
# 'k2':'罗梦竹, 北京, 175, 49, 18623423421',
# 'k3':{'叶梓萱': '上海', '171': '49','phone': '18042432324'},
# }
# def p(a):
#     if len(i) > 2 and type(i) is not dict:
#         new_i = i[:2]
#         d[k] = new_i
#     elif type(i) is dict:
#         count = 0
#         for line,val in list(i.items()):
#             count += 1
#             if count > 2:
#                 del i[line]
#                 continue
# for k,i in d.items():
#     if len(i) > 2:
#         p(i)
#     else:
#         continue
# print(d)



# 闭包的概念：在函数中加一个用了上一级变量的函数并且return此函数，
# 导致一级函数在结束时并没有从内存中被抹去而是二级函数以一级函数的形式存在等待被调用



# def puke():
#     def pai(name):
#         d = {}.fromkeys(['J','K','Q','A',2,3,4,5,6,7,8,9,10],name)
#         for i in d.items():
#             i = i[::-1]
#             a.append(i)
#
#
#     a = []
#     b = ['黑桃','草花','红心','梅花']
#     for i in b:
#         pai(i)
#     print(a)
# puke()



# def max_min(list):
#     max_a = max(a)
#     min_a = min(a)
#     d = {}
#     d['max'] = int(max_a)
#     d['min'] = int(min_a)
#     print(d)
#
# a = input(':').strip().split(',')
# print(a)
# max_min(a)


# def a(name,shu):
#     def chang(r,k):      #长*宽
#         s = r * k
#         print(s)
#     def zheng(r):        #长**2
#         s = r**2
#         print(s)
#     def yuan(r):           #ΠR**2
#         s = r**2*3.14
#         print(s)
#
#     if name is '1':
#         shu = int(shu)
#         yuan(shu)
#     elif name is '2':
#         shu = int(shu)
#         zheng(shu)
#     elif name is '3':
#         shu1 = shu.split(',')
#         num = [int(i) for i in shu1]
#         chang(num[0],num[1])
# info = '''
# 1.圆形
# 2.正方形
# 3.长方形
# '''
# print(info)
# name = input(':').strip()
# shu = input(':').strip().replace(' ',',')
# a(name,shu)




# def c(x):
#     return x**x
# a = int(input(':').strip())
# print(c(a))




def denglu(func):
    def inner():
        global state
        if state == 0:
            name = input('name:').strip()
            paswd = input('paswd:').strip()
            if name == name1 and paswd == pasd:
                state = 1
                print('welcome')
                func()
            else:
                print('wrong')
        else:
            print('已登录')
            func()
    return inner
@denglu
def a():
    print('1'.center(20,'-'))
@denglu
def b():
    print('2'.center(20,'-'))
@denglu
def c():
    print('3'.center(20,'-'))
@denglu
def d():
    print('4'.center(20,'-'))
name1 = '1'
pasd = '2'
state = 0
c()
a()
b()
d()




#生成器和迭代器的区别？
#生成器被next调用最后stop跳出后无法返回下个值
#迭代器被next调用其能一直跳出值 ，可遍历，可循环





# def logger(filename,channel='file'):
#     main1 = yield                              #根据指令输出日志
#     f = open(filename,'a')
#     f.write(main1)
#     f.close()
# logobj = logger(filename=r'C:\Users\Administrator\Desktop\22222.txt',channel='both')
# logobj.__next__()
# logobj.send('user alex login success')




# d = {}
# f = open(r'C:\Users\Administrator\Desktop\22222.txt','r+')
# for i in f:
#     i = i.split()
#     d[i[2]] = i
# f.seek(0)
# f.truncate()                                     #处理文件数据使数据整齐
# for i in d.values():
#     f.write(','.join(i)+'\n')
# f.close()




# d = {}
# f = open(r'C:\Users\Administrator\Desktop\22222.txt','r')
# for i in f:
#     i = i.strip().split(',')
#     d[i[2]] = i                               #文件数据形成字典
# f.close()
# print(d)




# num = [1,3,5,6,7,8]
# a = filter(lambda x:x if x % 2 ==0 else False,num)
#print(list(a))                                   #用filter筛选偶数




# def sb(x):
#     return x+'_sb'
# res = map(sb,name)                                #给列表加新内容用map
# print(list(res))
# name=['alex','wupeiqi','yuanhao','nezha']
# a = map(lambda x:x+'_sb',name)
# print(list(a))




# ortfolio = [
#     {'name': 'IBM','shares': 100, 'price': 91.1},
#     {'name': 'AAPL','shares': 50, 'price': 543.22},
#     {'name': 'FB','shares': 200,'price': 21.09},
#     {'name': 'HPQ','shares': 35, 'price': 31.75},
#     {'name': 'YHOO','shares': 45, 'price': 16.35},
#     {'name': 'ACME','shares': 75, 'price': 115.65}
# ]
# def total(name):                                           #通过名字查询信息
#     count = 0
#     while count < 6:
#         if name in ortfolio[count]['name']:
#             tota = ortfolio[count]['shares'] * ortfolio[count]['price']
#             print('total:%.2f'% tota)
#             break
#         else:
#             print('oh !! wrong !!!')
#             break
# def contrast(price1):                                  #通过价格查询信息
#     global num1
#     conut = 0
#     num1 = []
#     while conut < 6:
#         num1.append(ortfolio[conut]['price'])
#         conut += 1
#     a = filter(lambda x:x > price1,num1)
#     yield a
# name = input('you chose:').upper().strip()
# total(name)
# f = contrast(100)
# r = f.__next__().__next__()
# print(ortfolio[num1.index(r)])




# def cap(list,letter):
#     conut = 0                               #首字母大写
#     for  i in list:
#         if i.startswith(letter):
#             i = i.capitalize()
#             li[conut] = i
#             conut += 1
#         else:
#             conut += 1
#     print(li)





# def sor(list,n):
#     print(sorted(li, key=lambda x: x[n-1], reverse=True))
# li = ['alex', 'egon', 'smith', 'pizza', 'alen']
# sor(li,2)





# def de(n):          #删除指定行
#     del d[n-1]
#     print(d)
# def deal():                                  #处理文件内容
#     f = open(r'C:\Users\Administrator\Desktop\22222.txt','r',encoding='ANSI')
#     for i in f:                          #1.  读取内容 每行去空格进列表D
#         i = i.strip()
#         d.append(i)
#     f.close()
#     conut = 0
#     for line in d:                        #2.   删除空白行
#         if len(line) == 0:
#             d.pop(conut)
#             conut += 1
#         else:
#             conut += 1
# d = []
# deal()
# print(list(enumerate(d,1)))
# n = int(input('要删除的行数:'))
# de(n)
# svae_back()
# def svae_back(d):
#     f = open(r'C:\Users\Administrator\Desktop\22222.txt','r+',encoding='ANSI')   #存入处理后的内容
#     f.seek(0)                                #光标到开头
#     f.truncate()                                #清空文件
#     for i in d:                               #每个元素按一行写入文件
#         f.write(i + '\n')
#     f.close()



# def deal():
#     f = open(r'C:\Users\Administrator\Desktop\22222.txt', 'r', encoding='ANSI')
#     for i in f:
#         i = i.strip()
#         d.append(i)
#     f.close()
#     conut = 0
#     for i in d:
#         if len(i) == 0 :
#             d.pop(conut)
#             conut += 1
#         else:
#             conut += 1
# def save_back(d):
#     f = open(r'C:\Users\Administrator\Desktop\22222.txt', 'w', encoding='ANSI')
#     f.seek(0)
#     f.truncate()
#     for i in d:
#         f.write(i+'\n')
#     f.close()
# d = []
# deal()
# name = input(':').strip()
# if name in d:
#     exit('用户命已存在')
# else:
#     d.append(name)
# save_back(d)



# def save_back():
#     f = open(r'C:\Users\Administrator\Desktop\22222.txt', 'w', encoding='ANSI')
#     f.seek(0)
#     f.truncate()
#     for i in d.values():
#         f.write(','.join(i) + '\n')
#     f.close()
# def deal():
#     f = open(r'C:\Users\Administrator\Desktop\22222.txt', 'r', encoding='ANSI')
#     for i in f:
#         i = i.strip().split(',')
#         d[i[1].strip()] = i
#     f.close()
# def de(num):
#     del d[num]
#     print(d)
# d = {}
# deal()
# id = input('del id:').strip()
# de(id)
# save_back()
# print('ok!!')


# def deal():                      #处理文件
#     f = open(r'C:\Users\Administrator\Desktop\22222.txt', 'r', encoding='ANSI')
#     for i in f:
#         i = i.strip().split(',')           #每一行去头尾空格 空白处用，代替形成列表
#         d[i[1].strip()] = i               #列表的其中一项成key 一行成val
#     f.close()
# def rev(id,name):                        #改文件里用户的名字
#     d[id][0] = name                      #找到对应的key 进行修改
# def save_back():                        #保存修改的数据
#     f = open(r'C:\Users\Administrator\Desktop\22222.txt', 'w', encoding='ANSI')
#     f.seek(0)
#     f.truncate()                         #清空原数据
#     for i in d.values():
#         f.write(','.join(i) + '\n')          #将字典的每一个val转变成字符串用，分开  写入文件
#     f.close()
# d = {}
# deal()
# id = input(':').strip()
# name = input(':').strip()
# rev(id,name)
# save_back()
# print('ok!!!')





# import time
# def tim(func):                           #计算函数运算时间
#     def inner():
#         sta_time = time.time()            #开始执行的时间
#         func()                             #执行函数
#         end_time = time.time()              #函数结束的时间
#         run_time = end_time - sta_time      #函数运作的时间
#         print('%f'% run_time)
#     return inner
# @tim                                #语法糖：用装饰器功能使tim函数在不改变原函数的情况下
# def c():                             #在c函数执行前执行 与想要绑定的函数绑定在一起
#     def sor(list,n):
#         print(sorted(li, key=lambda x: x[n-1], reverse=True))
#     li = ['alex', 'egon', 'smith', 'pizza', 'alen']
#     sor(li,2)
#     time.sleep(1)          #停1秒动作
# @tim
# def d():
#     name=['alex','wupeiqi','yuanhao','nezha']
#     a = map(lambda x:x+'_sb',name)
#     print(list(a))
#     time.sleep(1)
# @tim
# def a():
#     num = [1,3,5,6,7,8]
#     a = filter(lambda x:x if x % 2 ==0 else False,num)
#     print(list(a))
#     time.sleep(1)
# a()
# d()
# c()



# lambda是匿名函数，有输入有输出
# a = [1,23,4]
# b = lambda x:sum(x)
# print(b(a))



# while True:                                 #只能输入数字的优化
#     a = input(':')
#     if a.strip().isdigit() == 0:
#         print('11111')
#         continue
#     else:
#         print('222222')
#         break
# print('3333333')



#题目：写一个摇骰子游戏，要求用户压大小，赔率一赔一。要求：
# 1.三个骰子（dice1，2，3）
# 2.每个骰子的值从1-6
# 3.摇大小
# 4.每次打印摇出来3个骰子的值。
# def dice_game():
#     def yes():                          #猜对的结果
#         print('yes!')
#         print('恭喜！现在还有%dRMB！！' % (money + number))
#     def no():                            #猜错的结果
#         if money > 20:
#             print('no')
#             print('真可惜就差一点点就猜对了！')
#         else:
#             print('no')
#             print('真可惜就差一点点就猜对了！你只有%dRMB' % (money - number))
#     if money > 10:
#         d = list(range(1,19))
#         choose = input(':').strip()
#         if choose == 'q':
#             return
#         while True:                                #检测赌注的值是否是数字
#             number = input('赌注:')
#             if number.strip().isdigit():
#                 number = int(number)
#                 break
#             else:
#                 print('输入格式错误，再输一次:')
#                 continue
#         dice1,dice2,dice3 = random.randint(1,6),random.randint(1,6),random.randint(1,6)
#         dice = dice2 + dice3 + dice1
#         info ='''
#         First : %d
#         Second: %d
#         Third : %d
#         Sum   : %d
#         '''%(dice1,dice2,dice3,dice)
#         print(info)
#         if choose == '大':
#             if dice in d[9:]:
#                 yes()
#             else:
#                 no()
#         elif choose == '小':
#             if dice in d[:9]:
#                 yes()
#             else:
#                 no()
#     else:
#         print('抱歉账户金额不够了！只有%dRMB'%money)
# import random
# money = 100
# dice_game()


# import random
# sum1 = 0
# for i in range(0,3):
#     i = random.randint(1, 6)
#     print('骰子的值：%d'%i)
#     sum1 = sum1 + i
# print('总和：%d'%sum1)





# print('\033[5;34m 111111111\033[0m')





